package com.work.service.impl;

import com.work.dao.AddressDao;
import com.work.dao.UserDao;
import com.work.pojo.Address;
import com.work.pojo.GoodsType;
import com.work.pojo.User;
import com.work.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 用户服务impl
 *
 * @author gy
 * &#064;date 2022/09/29
 * @version 1.0.0
 * @since 1.0.0
 */
@Service
@Transactional(rollbackFor = Exception.class,readOnly = true,propagation = Propagation.SUPPORTS)
public class UserServiceImpl implements UserService {
	@Autowired
	private AddressDao addressDao;
	@Autowired
	private UserDao userDao;
	@Override
	public User login(String username, String password) {
		return userDao.login(username,password,1);
	}
	
	@Override
	@Transactional(rollbackFor = Exception.class)
	public boolean register(User user) {
		return userDao.register(user);
	}
	
	@Override
	public boolean checkUserName(String username) {
		return userDao.checkUserName(username) != null;
	}
	
	@Override
	public User adminLogin(String username, String password) {
		return userDao.login(username,password,0);
	}
	
	@Override
	public List<User> listUser() {
		return userDao.listUser();
	}
	
	@Override
	public void deleteUserById(Integer id) {
		userDao.deleteUserById(id);
	}
	
	@Override
	public List<User> searchUserByNameAndGender(String username, String gender) {
		return userDao.searchUserByNameAndGender(username, gender);
	}

	@Override
	public List<User> getAllUserList() {
		return userDao.listUser();
	}

	@Override
	public List getAddress(Integer id) {
		return addressDao.getAddress(id);
	}

	@Override
	public void deleteAddress(Integer id) {
		addressDao.deleteAddress(id);
	}

	@Override
	public void defaultAddress(Integer id, Integer uid) {
		addressDao.setCommonById(uid);
		addressDao.setDefaultById(id);

	}

	@Override
	public void updateAddress(Address address) {
		addressDao.updateAddress(address);
	}

	@Override
	public void addAddress(Address address) {
		addressDao.addAddress(address);
	}

}
